
package com.zyj.eps.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 *
 * @author chen ming yang
 *
 *WebMvcConfigurerAdapter 具有跨域能力
 */
@Configuration//声明明WebConfig是全局配置类
public class WebConfig extends WebMvcConfigurerAdapter{
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//允许访问的路径
                .allowedOrigins("Http://localhost:8080","Http://localhost:8081","null")//请求来源
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")//方法
                .allowCredentials(true)//允许携带
                .maxAge(3600);//最大时间
    }
}

/*package com.zyj.eps.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;*/
/*

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
*/

/**
 * @author super
 * @date 2022/3/22 20:12
 * WebMvcConfigurerAdapter 具有跨域能力
 */
/*@Configuration//声明明WebConfig是全局配置类
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//允许访问的路径
                *//*.allowedOrigins("*")*//*
                .allowedOrigins("Http://localhost:8080","Http://localhost:8081","null")//请求来源
                .allowedMethods("GET","POST","PUT","OPTIONS","DELETE")//方法
                .allowCredentials(true)//允许携带
                .maxAge(3600);//最大时间
    }

}*/


